<html lang="en">
<head>
    <title>注册游记管理</title>
<#include  "../common/header.ftl">
    <script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>

    <script>
        $(function () {
            //集成富文本编辑器
            var ck = CKEDITOR.replace('content', {
                //图片服务器路径 存放已经服务中图片
                filebrowserBrowseUrl: '/服务器Url',

                //本地图片上传服务中图片请求Url
                filebrowserUploadUrl: '/images.do'
            })


            //模态框二级联动
            $("#strategySelect").change(function () {
                var strategyId = $(this).val();
                if (strategyId == -1) {
                    var html = "<option value='-1'>--请选择--</option>";
                    $("#catalog").html(html);
                }
                //根据大攻略id查询攻略分类数据
                $.get("/strategyDetail/getCatalogByStrategyId.do", {strategyId: strategyId}, function (data) {
                    var html = "<option value='-1'>--请选择--</option>";
                    $.each(data, function (index, item) {
                        html += "<option value='" + item.id + "'>" + item.name + "</option>"
                    });
                    $("#catalog").html(html);
                })
            })

            //点击修改/添加弹出模态框
            $(".editBtn").click(function () {
                //清空表单数据
                $("#editForm")[0].reset();
                var json = $(this).data("json");
                if (json) {
                    //回显模态框数据
                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm input[name='title']").val(json.title);
                    $("#editForm input[name='coverUrl']").val(json.coverUrl);
                    $("#coverUrl").attr("src", json.coverUrl);
                    $("#editForm input[name='title']").val(json.title);
                    $("#editForm input[name='sequence']").val(json.sequence);
                    $("#editForm select[name='strategy.id']").val(json.strategyId);
                    //根据大攻略id查询攻略分类数据
                    $.get("/strategyDetail/getCatalogByStrategyId.do", {strategyId: json.strategyId}, function (data) {
                        var html = "<option value='-1'>--请选择--</option>";
                        $.each(data, function (index, item) {
                            html += "<option value='" + item.id + "'>" + item.name + "</option>"
                        });
                        $("#catalog").html(html);
                        //二级下拉框的回显
                        $("#catalog").val(json.catalog);
                    })
                    //富文本编辑框中的内容回显
                    $.get("/strategyDetail/getContentByDetailId.do", {detailId: json.id}, function (data) {
                        ck.setData(data.content);
                    })
                }
                //弹出模态框
                $("#strategyModal").modal("show");
            })


            //提交模态框表单信息
            $("#saveBtn").click(function () {
                $("#editForm").submit();
            })

        })
    </script>
    <style>
        #strategyModal img {
            width: 100%;
        }

        #strategyModal .modal-body {
            max-height: 600px;
            overflow-y: auto;
        }
    </style>
</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu='strategyDetail'>

<div class="container " style="margin-top: 20px">
<#include  "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
        <#include  "../common/menu.ftl">
        </div>

        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略文章管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyDetail/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}">
                </div>
                <button id="btn_query" class="btn btn-info"><span class="glyphicon glyphicon-search"></span> 查询</button>
                <a href="javascript:void(-1);" class="btn btn-success editBtn" id="addStrategyBtn">添加攻略文章</a>
            </form>

            <table class="table table-striped table-hover">
                <thead>
                <th>编号</th>
                <th>标题</th>
                <th>封面</th>
                <th>发布时间</th>
                <th>排序</th>
                <th>攻略类别</th>
                <th>状态</th>
                <th>操作</th>
                </tr>
                </thead>

            <#list result.list as entity>
                <tr>
                    <td>${entity_index + 1}</td>
                    <td>${entity.title!}</td>
                    <td><img src="${entity.coverUrl!}" width="50px"></td>
                    <td>${(entity.releaseTime?string("yyyy-MM-dd"))!}</td>
                    <td>${(entity.sequence)!}</td>
                    <td>${(entity.catalog.name)!}</td>
                    <td>${(entity.stateDisplay)!}</td>
                    <td>
                        <a href="javascript:;" data-json='${entity.jsonString}' class="editBtn">修改</a>&nbsp;&nbsp;
                    </td>
                </tr>
            </#list>

            </table>
        <#include "../common/page.ftl">
        </div>
    </div>
</div>
<#--攻略文章 编辑/添加 模态框-->
<div id="strategyModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal " method="post" enctype="multipart/form-data"
                      action="/strategyDetail/saveOrUpdate.do" style="margin: -3px 20px">
                    <input id="id" type="hidden" name="id"/>
                    <input  type="hidden" name="coverUrl"/>
                    <div class="form-group inline">
                        <label class="col-sm-4 control-label">标题</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title" placeholder="攻略标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="200px"/>
                            <input type="file" class="form-control" name="file">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属攻略</label>
                        <div class="col-sm-6">
                            <select id="strategySelect" name="strategy.id" class="form-control form-control-chosen">
                                <option value="-1">--请选择--</option>
                            <#list strategys as s>
                                <option value="${s.id}">${s.title}</option>
                            </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">攻略类别</label>
                        <div class="col-sm-6">
                            <select id="catalog" name="catalog.id" class="form-control form-control-chosen">
                                <option value="-1">--请选择--</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">是否发布</label>
                        <div class="col-sm-6">
                            <select class="form-control" autocomplete="off" name="state">
                                <option value="0">是</option>
                                <option value="1">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">排序</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sequence" placeholder="序列号">
                        </div>
                    </div>
                    <textarea id="content" name="strategyContent.content" class="ckeditor" cols="5" rows="5">
                    </textarea>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>

</body>
</html>